VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsEjeComando"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False

Public Function Ejec_Comando_1(sProcAlm As String, ParamArray listaParametros()) As ADODB.Recordset
Dim RsComando As ADODB.Recordset
Set RS = Nothing
On Error GoTo Er
    nCant = UBound(listaParametros()) + 1
    sCadena = ""
    For i = 0 To nCant - 1
        sCadena = sCadena & "'" & listaParametros(i) & "',"
    Next i
    If nCant >= 0 Then sCadena = " " & Left(sCadena, Len(sCadena) - 1)
    SQL = Trim$(sProcAlm) & sCadena
    
   Set RS = New ADODB.Recordset
    RS.CursorLocation = adUseClient
    RS.Open SQL, Cnn, adOpenDynamic
    xx = RS.RecordCount
    Set Ejec_Comando_1 = RS
    Exit Function
Er:
  MsgBox Err.Description
  Resume Next
End Function

Public Function Ejec_Comando_2(sProcAlm As String, ParamArray listaParametros()) As ADODB.Command
On Error GoTo Er
    nCant = UBound(listaParametros()) + 1
    Set Cmd = New ADODB.Command
    With Cmd
        .ActiveConnection = Cnn
        .CommandType = adCmdStoredProc
        .CommandTimeout = 0
        .CommandText = sProcAlm$
        If nCant <> 0 Then
            For i = 1 To nCant
                Cmd(i) = listaParametros(i - 1)
                cadena = cadena & ", " & listaParametros(i - 1)
            Next i
        End If
        .Execute
    End With
    Set Ejec_Comando_2 = Cmd
    Exit Function
Er:
    MsgBox Err.Description
End Function


Public Function EjecutaComando(strSQL As String) As Boolean
    'Funcion Carga Recordset
    Dim lngErr As Long, strErr As String
    On Error GoTo Falla
    
    'Inicia la Transaccion
    Cnn.BeginTrans
            
    'Ejecuta Comando
    Cnn.Execute strSQL
    
    'Termina la Transaccion
    Cnn.CommitTrans
    
    'Cierra la Conexion
    'Desconectarse CNN
    
    'Todo fue con exito
    EjecutaComando = True
    
    Exit Function
Falla:
    lngErr = Err.Number: strErr = Err.Description
    Cnn.RollbackTrans
    Err.Raise lngErr, "CargarRs", strErr
End Function

